package com.ruoyi.part.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.part.domain.DmsPartsPurchaseOrderDetail;
import com.ruoyi.part.service.IDmsPartsPurchaseOrderDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 零件采购详细Controller
 * 
 * @author liuchuanfa
 * @date 2024-03-17
 */
@RestController
@RequestMapping("/part/purchaseDetail")
public class DmsPartsPurchaseOrderDetailController extends BaseController
{
    @Autowired
    private IDmsPartsPurchaseOrderDetailService dmsPartsPurchaseOrderDetailService;

    /**
     * 查询零件采购详细列表
     */
    @PreAuthorize("@ss.hasPermi('part:purchaseDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsPartsPurchaseOrderDetail dmsPartsPurchaseOrderDetail)
    {
        startPage();
        List<DmsPartsPurchaseOrderDetail> list = dmsPartsPurchaseOrderDetailService.selectDmsPartsPurchaseOrderDetailList(dmsPartsPurchaseOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出零件采购详细列表
     */
    @PreAuthorize("@ss.hasPermi('part:purchaseDetail:export')")
    @Log(title = "零件采购详细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsPartsPurchaseOrderDetail dmsPartsPurchaseOrderDetail)
    {
        List<DmsPartsPurchaseOrderDetail> list = dmsPartsPurchaseOrderDetailService.selectDmsPartsPurchaseOrderDetailList(dmsPartsPurchaseOrderDetail);
        ExcelUtil<DmsPartsPurchaseOrderDetail> util = new ExcelUtil<DmsPartsPurchaseOrderDetail>(DmsPartsPurchaseOrderDetail.class);
        util.exportExcel(response, list, "零件采购详细数据");
    }

    /**
     * 获取零件采购详细详细信息
     */
    @PreAuthorize("@ss.hasPermi('part:purchaseDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsPartsPurchaseOrderDetailService.selectDmsPartsPurchaseOrderDetailById(id));
    }

    /**
     * 新增零件采购详细
     */
    @PreAuthorize("@ss.hasPermi('part:purchaseDetail:add')")
    @Log(title = "零件采购详细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsPartsPurchaseOrderDetail dmsPartsPurchaseOrderDetail)
    {
        return toAjax(dmsPartsPurchaseOrderDetailService.insertDmsPartsPurchaseOrderDetail(dmsPartsPurchaseOrderDetail));
    }

    /**
     * 修改零件采购详细
     */
    @PreAuthorize("@ss.hasPermi('part:purchaseDetail:edit')")
    @Log(title = "零件采购详细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsPartsPurchaseOrderDetail dmsPartsPurchaseOrderDetail)
    {
        return toAjax(dmsPartsPurchaseOrderDetailService.updateDmsPartsPurchaseOrderDetail(dmsPartsPurchaseOrderDetail));
    }

    /**
     * 删除零件采购详细
     */
    @PreAuthorize("@ss.hasPermi('part:purchaseDetail:remove')")
    @Log(title = "零件采购详细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsPartsPurchaseOrderDetailService.deleteDmsPartsPurchaseOrderDetailByIds(ids));
    }
}
